//
//  QRCodeViewController.swift
//  LVWeibo
//
//  Created by lv on 15/7/1.
//  Copyright © 2015年 lv. All rights reserved.
//

import UIKit

class QRCodeViewController: UIViewController,UITabBarDelegate {

    @IBOutlet weak var tabBar: UITabBar!
    
    @IBOutlet weak var widthCons: NSLayoutConstraint!
    @IBOutlet weak var heightCons: NSLayoutConstraint!
    
    @IBOutlet weak var topCons: NSLayoutConstraint!
    
    @IBOutlet weak var scanView: UIImageView!
    
    @IBAction func close(sender: UIBarButtonItem) {
        dismissViewControllerAnimated(true, completion: nil)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        tabBar.selectedItem = tabBar.items![0]
    }
    
    override func viewDidAppear(animated: Bool) {
        
        // 冲击波动画
        scanAnimation()
    }
    
    // MARK:- 冲击波动画
    private func scanAnimation() {
        // 停止图层动画
        scanView.layer.removeAllAnimations()
        
        // 设定动画起始约束
        topCons.constant = -heightCons.constant
        
        // 更新视图布局
        view.layoutIfNeeded()
        
        // 开始动画
        UIView.animateWithDuration(1.5) { () -> Void in
            self.topCons.constant = self.heightCons.constant
            UIView.setAnimationRepeatCount(MAXFLOAT)
            self.view.layoutIfNeeded()
        }
    }
    
    
    
    //MARK:- 选中tabBar代理方法
    func tabBar(tabBar: UITabBar, didSelectItem item: UITabBarItem) {
        heightCons.constant = widthCons.constant * (item.tag == 1 ? 0.5 : 1)
        scanAnimation()
    }
    
}
